package cn.lanqiao.common.identifyingCode;

import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.geometry.Positions;

import java.io.InputStream;
import java.io.OutputStream;

public class ThumbnailatorUtils
{
  public static void sizeImage(InputStream inputStream, OutputStream outputStream, double quality, int width, int height)
    throws Exception
  {
    Thumbnails.of(new InputStream[] { inputStream }).size(width, height).outputQuality(quality).toOutputStream(outputStream);
  }
  
  public static void sizeImage(InputStream inputStream, OutputStream outputStream, double quality, boolean keepAspectRatio, int width, int height)
    throws Exception
  {
    Thumbnails.of(new InputStream[] { inputStream }).size(width, height).outputQuality(quality).keepAspectRatio(keepAspectRatio).toOutputStream(outputStream);
  }
  
  public static void sourceRegionImage(InputStream inputStream, OutputStream outputStream, double quality, Positions positions, int width, int height)
    throws Exception
  {
    Thumbnails.of(new InputStream[] { inputStream }).sourceRegion(positions, width, height).size(width, height).outputQuality(quality).toOutputStream(outputStream);
  }
  
  public static void scaleImage(InputStream inputStream, OutputStream outputStream, double quality, double scale)
    throws Exception
  {
    Thumbnails.of(new InputStream[] { inputStream }).scale(scale).outputQuality(quality).toOutputStream(outputStream);
  }
  
  public static void scaleImage(InputStream inputStream, OutputStream outputStream, double quality, double widthScale, double heightScale)
    throws Exception
  {
    Thumbnails.of(new InputStream[] { inputStream }).scale(widthScale, heightScale).outputQuality(quality).toOutputStream(outputStream);
  }
  
}
